#
require 'hpricot'
require 'open-uri'
require 'iconv'

def wikipedia cname
	i = Iconv.new 'utf-8','gb2312'
	cname = i.iconv cname
	i.close
	wikipedia_utf8 cname
end

def wikipedia_utf8 cname
	url = 'http://zh.wikipedia.org/w/index.php?title='+cname+'&variant=zh-cn'
	as=[]
	uri =  URI::encode url
	begin
		doc = Hpricot open uri
		#puts doc
		(doc/'tr').each{|tr|
			b = tr.at('td/b')
			next if b==nil
			if (b.html=='类型' or  b.html=='题材类型')
				(tr/'a').each{|a|
					as<<a.html
				}
				if as.length==0
					(tr/'td').each{|a|
						as<<a.html
					}
				end
				break
			end
		}
	rescue Interrupt=>e
		as<<'neterr'
	rescue 
		as<<'neterr'
	end
	as =['empty']if as.length<1
	as	
end